package ink.yql.service.Impl;

import ink.yql.dao.ReturnsDao;
import ink.yql.model.Returns;
import ink.yql.service.ReturnsService;
import ink.yql.util.RestObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ReturnsServiceImpl implements ReturnsService {
    @Autowired
    private ReturnsDao returnsDao;


    @Override
    public RestObject getByPid(Integer pid) {
        if (pid == null) {
            return RestObject.builder().code("400").message("请传输一个正确的数据").build();
        }
        List<Returns> list = returnsDao.getByPid(pid);
        return RestObject.builder().code("200").message("查询回报成功").data(list).build();
    }

    @Override
    public RestObject addOne(Returns returns) {
        Integer one = returnsDao.addOne(returns);
        return RestObject.builder().code("200").message("添加回报成功").build();
    }

    @Override
    public RestObject update(Returns returns) {
        Integer one = returnsDao.update(returns);
        return RestObject.builder().code("200").message("更新回报成功").build();
    }

    @Override
    public RestObject deleteRid(Integer rid) {
        Integer one = returnsDao.deleteByRid(rid);
        return RestObject.builder().code("200").message("删除回报").build();
    }
}
